<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>分类列表</title>
    <link rel="stylesheet/less" href="../../../static/css/index.less"/>
    <link rel="stylesheet" href="../../../static/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../../static/css/jquery.pagination.css"/>
    <script src="../../../static/js/jquery-1.12.3.js"></script>
    <script src="../../../static/js/less.min.js"></script>
    <script src="../../../static/layui/layui.js"></script>
    <script src="../../../static/js/ajaxfileupload.js"></script>
    <script src="../../../static/layer/layer.js"></script>
</head>
<style>
    .table_td_img {
        width: 50px;
        height: 50px;
        padding: 3px
    }
</style>
<body class="layui-layout-body">

{% include "admin/top.html" %}
{% include "admin/left.html" %}

<div id="box" class="fl">
    <div class="content">
        <h3><a>分类列表</a></h3>
        <div class="search">
                <input type="text" name="search" class="ipt" id="cname" placeholder="分类名称" value="">
                <select name="status" id="sid">
                    <option value="">全部</option>
                    {% if sub %}
                    {% for d in sub %}
                    <option value="{{ d.sid }}">{{ d.typeName }}</option>
                    {% endfor %}
                    {% endif %}
                </select>
                <button onclick="get_data(1)" class="s_button">搜索</button>
        </div>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <thead>
            <tr>
                <th width="4%">分类ID</th>
                <th width="12%">分类名称</th>
                <th width="20%">主题名称</th>
                <th width="10%">添加时间</th>
                <th width="10%">状态</th>
                <th width="20%">操作</th>
            </tr>
            </thead>

            <tbody id="result">

            </tbody>
        </table>
            <div class="ui-pagination-container">

            </div>
    </div>
</div>
<input type="hidden" id="p" value="1">
</body>
</html>

<script>
    get_data(1);
    function get_data(p){
        var cname = $('#cname').val();
        var sid = $('#sid').val();
        $.ajax({
            url:"/admin/classify_list_post",
            type:"post",
            data:{
                'cname':cname,
                'sid':sid,
                'p':p
            },
            dataType:"json",
            success:function(msg){
                var q = '';
                if (msg.status == 1){
                    for (var i = 0; i < msg.res.length; i++){
                        q += '<tr>';
                        q += '<td>' + msg.res[i].tid + '</td>';
                        q += '<td>' + msg.res[i].courseName + '</td>';
                        q += '<td>' + msg.res[i].typeName + '</td>';
                        q += '<td>' + msg.res[i].addTime + '</td>';
                        if (msg.res[i].status == 0){
                            q += '<td>禁用</td>';
                        }else {
                            q += '<td>激活</td>';
                        }
                        q += '<td><a class="course_commit" onclick="cilck_btn(' + msg.res[i].tid + ', 0)" name="edit">编辑</a>';
                        if (msg.res[i].status == 0){
                            q += '<a class="course_commit" onclick="cilck_btn(' + msg.res[i].tid + ', 1)" name="unlock">激活</a>';
                        }else {
                            q += '<a class="course_commit" onclick="cilck_btn(' + msg.res[i].tid + ', 2)" name="lock">锁定</a>';
                        }
                        q += ' <a class="course_commit" onclick="cilck_btn(' + msg.res[i].tid + ', 3)" name="delete">删除</a>';
                        q += '</td></tr>';
                    }
                }else {
                    q += '<td colspan="6">暂无数据</td>';
                }
                $('#result').html(q);
                $('.ui-pagination-container').html(msg.page);
                $('#p').val(msg.p);
            }
        })
    }
    function cilck_btn(uid, pid){
        if (pid == 0){
            location.href = '/admin/classify_detail.html?tid=' + uid;
            return false;
        }else if(pid == 1){
            var content = "激活分类";
        }else if(pid == 2){
            var content = '禁用分类';
        }else if(pid == 3){
            var content = '删除分类';
        }else {
            return false;
        }
        layer.open({
                content: content,
                btn: ['确认', '取消'],
                yes: function () {
                    $.ajax({
                        url: "/admin/update_classify_post",
                        type: "POST",
                        data: {
                            tid: uid,
                            pid: pid
                        },
                        success: function (data) {
                            if (data.status == 1) {
                                layer.msg("操作成功", {time: 2000}, function () {
                                    get_data($('#p').val());
                                })
                            } else {
                                layer.msg("操作失败！")
                            }
                        }
                    })
                },
                btn2: function (index, layero) {
                }
                ,
                cancel: function () {
                    //右上角关闭回调
                }
            });
    }



</script>


